﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MpSoft.Library.BUSS.Categories;

namespace MpSoft.Web.AdminCP.Controls
{
    public partial class LoadModules : System.Web.UI.UserControl
    {
        #region var

        private string controlName = string.Empty;

        #endregion

        #region Method

        private UserControl LoadUserControl(string ControlPath)
        {
            try
            {
              return Page.LoadControl(ControlPath) as UserControl;
            }
            catch (HttpException ex)
            {
                Session["MessError"] = ex.Message.ToString();
                Session["MessError"] = Session["MessError"].ToString() + "</br></br>" +
                    ex.StackTrace.ToString();
                return Page.LoadControl("~/AdminCP/Controls/Error.ascx") as UserControl;
            }
        }

        private void LoadControl()
        {
            this.Controls.Add(LoadUserControl("~/AdminCP/Controls/" + GetManageControl()));
        }

        private string GetManageControl()
        {
            var listNav = NavigateBUSS.Navigate_ByDic();
            if (listNav.ContainsKey(this.controlName))
                return listNav[this.controlName].PathControl;
            return "HomeControl.ascx";
        }

        #endregion

        #region Event

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadControl();
        }

        #endregion

        #region Properties

        public string ControlName
        {
            set { controlName = value; }
            get { return controlName; }
        }

        #endregion
    }
}